package day20210702;

import java.util.Arrays;

/**
 * 1833. 雪糕的最大数量
 * 在给定硬币数量 \textit{coins}coins 的情况下，要买到最多的雪糕，应该买最便宜的雪糕
 *
 * @author lizy
 * @date 2021/07/02
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] relation = {1,3,2,4,1};
        System.out.println(solution.maxIceCream(relation,3));
    }

    public int maxIceCream(int[] costs, int coins) {
        Arrays.sort(costs);
        int count = 0;
        int n = costs.length;
        for (int i = 0; i < n; i++) {
            int cost = costs[i];
            if (coins >= cost) {
                coins -= cost;
                count++;
            } else {
                break;
            }
        }
        return count;
    }
}
